package com.adjaisd.scarecrow.testJava;

import com.adjaisd.scarecrow.entity.Device;
import com.adjaisd.scarecrow.entity.DeviceStatus;
import com.adjaisd.scarecrow.mapper.DeviceMapper;
import com.adjaisd.scarecrow.mapper.DeviceStatusMapper;
import com.adjaisd.scarecrow.service.DeviceStatusService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class testDeviceStatus {

    @Autowired
    DeviceMapper deviceMapper;

    @Autowired
    DeviceStatusService deviceStatusService;

    @Test
    void testUpdateOnline() {
        System.out.println(deviceStatusService.getDeviceStatusByID(5L));
    }

    @Test
    void testGetByID() {
        System.out.println(deviceStatusService.getDeviceStatusByID(100000L));
    }

    @Test
    void addDeviceStatusData() {
        QueryWrapper<Device> wrapper = new QueryWrapper<>();
        wrapper.lambda().gt(Device::getBindTime, 0L);
        List<Device> devices = deviceMapper.selectList(wrapper);
        for (Device device : devices) {
            DeviceStatus statusByID = deviceStatusService.getDeviceStatusByID(device.getId());
            if (statusByID == null) {
                DeviceStatus deviceStatus = new DeviceStatus(device.getId(), false, "正常", 0, true, "", true);
                deviceStatusService.addDeviceStatus(deviceStatus);
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    @Autowired
    DeviceStatusMapper deviceStatusMapper;

    @Test
    void testSelectInTags(){
        System.out.println(deviceStatusMapper.selectInTags("温度,湿度"));
    }

}
